<?php

/**
 * @file classes/journal/CTKTDAO.inc.php
 *
 * Copyright (c) 2003-2012 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * @class CTKTDAO
 * @ingroup journal
 * @see CTKT
 *
 * @brief Operations for retrieving and modifying CTKT objects.
 */

// $Id$


import ('classes.acct.CTKT');

class CTKTDAO extends DAO {
	var $cache;

	function _cacheMiss(&$cache, $id) {
		$CTKT =& $this->getCTKT();
		$cache->setCache($id, $CTKT);
		return $CTKT;
	}

	function &_getCache() {
		if (!isset($this->cache)) {
			$cacheManager =& CacheManager::getManager();
			$this->cache =& $cacheManager->getObjectCache('CTKT', 0, array(&$this, '_cacheMiss'));
		}
		return $this->cache;
	}

 	function &getCTKT($nam, $idphieu) {
		echo "bbbbbb";
		if (isset($idphieu))
			$result =& $this->retrieve(
				'SELECT * FROM CTKT".$nam. "  WHERE idphieu = ?', $idphieu
			);
		else
			$result =& $this->retrieve(
				"SELECT * FROM CTKT".$nam. )  ;


		$sectionsIterator = new DAOResultFactory($result, $this, '_returnCTKTFromRow');

		$sections = $returner ;
		$i = 0;


		while (($section =& $sectionsIterator->next())) {
			$sections[$i]['soct'] = $section->getsoct();
			$sections[$i]['ngct'] = $section->getngct();
			$i +=1;

			unset($section);
		}

		return $sections;


	}


 	function &getCTKT1($MATK) {
		if (isset($MATK))
			$result =& $this->retrieve(
				'SELECT * FROM CTKT WHERE MATK = ?', $MATK
			);
		else
			$result =& $this->retrieve(
				'SELECT * FROM CTKT');


		while (!$result->EOF) {
			$a = $result->GetRowAssoc(false);
			$CTKTs[] = $this->_returnCTKTFromRow($result->GetRowAssoc(false));
			$result->MoveNext();
		}

		$result->Close();
		unset($result);

		return $CTKTs;
	}

	function &_returnCTKTFromRow(&$row) {
		$CTKT = new CTKT($row['matk'], $row['tentk']);

		//HookRegistry::call('CTKTDAO::_returnCTKTFromRow', array(&$CTKT, &$row));
		
		return $CTKT;
	}


	
}

?>
